package com.yytek.job.controller;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.job.domain.PlanTaskTemplate;
import com.yytek.job.service.IPlanTaskTemplateService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 任务模板Controller
 * 
 * @author yytek-iot
 * @date 2022-07-29
 */
@Api(value = "任务模板控制器", tags = {"任务模板管理"})
@RestController
@RequestMapping("/templateJob")
public class PlanTaskTemplateController extends BaseController
{
    @Autowired
    private IPlanTaskTemplateService planTaskTemplateService;

    /**
     * 分页查询任务模板列表
     */
    @ApiOperation("分页查询任务模板列表")
    @RequiresPermissions("job:templateJob:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanTaskTemplate planTaskTemplate)
    {
        startPage();
        List<PlanTaskTemplate> list = planTaskTemplateService.selectPlanTaskTemplateList(planTaskTemplate);
        return getDataTable(list);
    }

    /**
     * 导出任务模板列表
     */
    @ApiOperation("导出任务模板列表")
    @RequiresPermissions("job:templateJob:export")
    @Log(title = "任务模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanTaskTemplate planTaskTemplate)
    {
        List<PlanTaskTemplate> list = planTaskTemplateService.selectPlanTaskTemplateList(planTaskTemplate);
        ExcelUtil<PlanTaskTemplate> util = new ExcelUtil<PlanTaskTemplate>(PlanTaskTemplate.class);
        util.exportExcel(response, list, "任务模板数据");
    }

    /**
     * 获取任务模板详细信息
     */
    @ApiOperation("获取任务模板详细信息")
    @RequiresPermissions("job:templateJob:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planTaskTemplateService.selectPlanTaskTemplateById(id));
    }

    /**
     * 新增任务模板
     */
    @ApiOperation("新增任务模板")
    @RequiresPermissions("job:templateJob:add")
    @Log(title = "任务模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanTaskTemplate planTaskTemplate) throws Exception {
        return toAjax(planTaskTemplateService.insertPlanTaskTemplate(planTaskTemplate));
    }

    /**
     * 修改任务模板
     */
    @ApiOperation("修改任务模板")
    @RequiresPermissions("job:templateJob:edit")
    @Log(title = "任务模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanTaskTemplate planTaskTemplate)
    {
        return toAjax(planTaskTemplateService.updatePlanTaskTemplate(planTaskTemplate));
    }

    /**
     * 删除任务模板
     */
    @ApiOperation("删除任务模板")
    @RequiresPermissions("job:templateJob:remove")
    @Log(title = "任务模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planTaskTemplateService.deletePlanTaskTemplateByIds(ids));
    }
}
